<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AuthModel
 *
 * @author wangnaixin
 */
namespace Admin\Model;
use Think\Model;
class AuthModel extends Model {
    //put your code here
    public function saveMenu($data){
        //判断 url 是否存在 不存在 添加  存在 修改
        $where = array(
            'controller'=>array('eq',$data['controller']),
            'function'=>array('eq',$data['function'])
        );
        $topMenu = $this->where($where)->find();
        if(!empty($topMenu)){
            $id = $topMenu['id'];
            $this->where($where)->save($data);
        }else{
            $id = $this->add($data);
        }
        return $id;
    }
    
    public function getAuthList(){
        $authList = $this->where("pid = 0")->select();
        foreach($authList as $k=>$v){
            $authList[$k]['subAuths'] = $this->where("pid = ".$v['id'])->select();
        }
        return $authList;
    }
}
